<?php
header("Content-Type: application/json; charset=UTF-8");
require_once 'db.php';

$id = isset($_GET['id']) ? intval($_GET['id']) : 0;
$user_id = isset($_GET['user_id']) ? intval($_GET['user_id']) : 0;

if ($id <= 0 || $user_id <= 0) {
    echo json_encode([
        'status' => 'error',
        'message' => '参数错误'
    ]);
    exit;
}

try {
    $sql = "SELECT * FROM feedbacks WHERE id = ? AND user_id = ?";
    $stmt = $conn->prepare($sql);
    $stmt->bind_param("ii", $id, $user_id);
    $stmt->execute();
    $result = $stmt->get_result();
    
    if ($result->num_rows > 0) {
        $feedback = $result->fetch_assoc();
        // 格式化时间
        $feedback['created_at'] = date('Y-m-d H:i', strtotime($feedback['created_at']));
        if ($feedback['reply_time']) {
            $feedback['reply_time'] = date('Y-m-d H:i', strtotime($feedback['reply_time']));
        }
        
        echo json_encode([
            'status' => 'success',
            'feedback' => $feedback
        ]);
    } else {
        throw new Exception("反馈不存在");
    }

} catch (Exception $e) {
    echo json_encode([
        'status' => 'error',
        'message' => $e->getMessage()
    ]);
} finally {
    if (isset($stmt)) $stmt->close();
    $conn->close();
}
?> 